package cryptut

import (
	"errors"
	"os"
)

func FileExists(path string) (bool) {
	_, err := os.Stat(path)
	if err == nil {
		return true
	}
	if os.IsNotExist(err) {
		return false
	}
	return false
}
func DirectoryExists(path string) (bool) {
	_, err := os.Stat(path)
	if err == nil {
		return true
	}
	if os.IsNotExist(err) {
		return false
	}
	return false
}
func FileReadAllBytes(path string) ([]byte,error) {
	if !FileExists(path) {
		return nil,errors.New("file is not exist")
	}
	return os.ReadFile(path)
}
func FileWriteAllBytes(path string,buf []byte) (bool) {
	if FileExists(path) {
		err := os.Remove(path)
		if err == nil {
			return true
		}
		return false
	}
	err :=os.WriteFile(path,buf,0666)
	if err == nil {
		return true
	}
	return false
}
